package com.club.football.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.club.football.dto.PageDto;
import com.club.football.dto.TeamSaveDto;
import com.club.football.entity.Team;
import com.club.football.req.TeamPageReq;
import com.club.football.service.TeamService;
import com.club.football.utils.R;
import com.club.football.vo.TeamPageVo;
import com.club.football.vo.TeamVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static com.club.football.common.CommonConstants.DEL_OK_MSG;

/**
 * 球队Controller
 *
 * @author 1
 * @date 2023/12/28
 */
@RestController
@RequestMapping("/team")
@AllArgsConstructor
public class TeamController {
    private TeamService teamService;

    /**
     * 球队保存
     *
     * @return {@link R}<{@link String}>
     */
    @PostMapping("/save")
    public R<String> save(@RequestBody @Valid TeamSaveDto teamSaveDto) {
        return teamService.teamSave(teamSaveDto);
    }

    /**
     * 球队分页查询
     *
     * @param pageDto 页数到页
     * @return {@link R}
     */
    @GetMapping("/page")
    public R<Page<TeamPageVo>> page(PageDto<Team> pageDto, TeamPageReq teamPageReq) {
        return teamService.teamPage(pageDto, teamPageReq);
    }

    @GetMapping("/info/{id}")
    public R<TeamVo> info(@PathVariable Long id) {

        return teamService.teamInfo(id);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return {@link R}<{@link String}>
     */
    @DeleteMapping("/remove/{id}")
    public R<String> remove(@PathVariable Long id) {
        teamService.removeById(id);
        return R.ok(DEL_OK_MSG);
    }
}
